local extension = Package("heroes_ev1")
extension.extensionName = "evolution"
--extension.game_modes_whitelist = {"brokenroyal_mode"}

local EV = require "packages/evolution/EV"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["heroes_ev1"] = "新约角色01-04",
  ["ev"] = "新约",
  ["ev_sp"] = "新约SP",
  ["#AddTargetsBySkill"] = "用于 %arg 的效果，%from 使用的 %arg2 增加了目标 %to",
}

Achilles = General(extension, "ev__achilles", "ev", 4)

local ev__jifengnutao = fk.CreateActiveSkill{
  name = "ev__jifengnutao",
  anim_type = "support",
  prompt = function(self)
    return "#ev__jifengnutao:::"..Self:usedSkillTimes(self.name) + 1
  end,
  card_num = function(self)
    return Self:usedSkillTimes(self.name) + 1
  end,
  target_num = 0,
  can_use = function(self, player)
    return not player:isNude()
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:addPlayerMark(player, "@jifengnutao-turn", #effect.cards)
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    room:setPlayerMark(player, "BypassTimesLimit", 1)
    U.askForUseVirtualCard(room, player, "ev__slash", nil, self.name)
    room:setPlayerMark(player, "BypassTimesLimit", 0)
  end,
}

local jifengnutao_trigger = fk.CreateTriggerSkill{
  name = "#jifengnutao_trigger",
  mute = true,
  anim_type = "offensive",
  events = {fk.TargetSpecifying},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.trueName == "slash"
    and data.card.skillName == "ev__jifengnutao" and data.tos and #AimGroup:getAllTargets(data.tos) == 1 then
      local targets = U.getUseExtraTargets(player.room, data, false, true)
      targets = table.filter(targets, function(p) return player.room:getPlayerById(p):getMark("jifengnutao-turn") > 0 end)
      return #targets > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = U.getUseExtraTargets(player.room, data, false, true)
    targets = table.filter(targets, function(p) return player.room:getPlayerById(p):getMark("jifengnutao-turn") > 0 end)
    local tos = player.room:askForChoosePlayers(player, targets, 1, 999, "#jifengnutao-choose:::"..data.card:toLogString(), self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(self.cost_data) do
      AimGroup:addTargets(room, data, pid)
    end
    room:sendLog{
      type = "#AddTargetsBySkill",
      from = player.id,
      to = self.cost_data,
      arg = self.name,
      arg2 = data.card:toLogString()
    }
  end,

  refresh_events = {fk.TargetConfirmed},
  can_refresh = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(target, "jifengnutao-turn")
  end
}

local jifengnutao_distance = fk.CreateDistanceSkill{
  name = "#jifengnutao_distance",
  frequency = Skill.Compulsory,
  correct_func = function(self, from)
    if from:hasSkill(self) and from:getMark("@jifengnutao-turn") > 0 then
      return 0 - from:getMark("@jifengnutao-turn")
    end
  end,
}

local ev__budiao = fk.CreateTriggerSkill{
  name = "ev__budiao",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name)
    and table.find(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = table.random(player:getCardIds('h'), 1)
    if data.from then
      --card = EV.askForCardChosen(player.room, data.from, player, "h", self.name)
      card = room:askForCardChosen(data.from, player, 'h', self.name)
    else
      card = player.room:askForCard(player, 1, 1, false, self.name, false, ".", "#ev__budiao-show")
      if #card > 0 then
        card = card[1]
      end
    end
    player:showCards({card})
    if table.every(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).number >= Fk:getCardById(card).number end) then
      room:loseHp(player, 1, self.name)
    else
      return true
    end
  end,
}

ev__jifengnutao:addRelatedSkill(jifengnutao_trigger)
ev__jifengnutao:addRelatedSkill(jifengnutao_distance)
Achilles:addSkill(ev__jifengnutao)
Achilles:addSkill(ev__budiao)

Fk:loadTranslationTable{
    ["ev__achilles"] = "阿喀琉斯",
    ["designer:ev__achilles"] = "KINGDOM43",
    ["ev__jifengnutao"] = "疾风怒涛",
    ["@jifengnutao-turn"] = "疾风怒涛",
    ["#ev__jifengnutao"] = "你可以弃置%arg张黑色牌",
    ["#jifengnutao-choose"] = "你可以为%arg额外增加任意个目标",
    [":ev__jifengnutao"] = "出牌阶段，你可弃置X张黑色牌，令你于本回合内与其他角色的距离-X；然后你视为使用【杀】，此【杀】可额外选择于本回合内成为过【杀】的目标的角色为目标（X为你于本回合内发动过此技能的次数+1）。",
    ["ev__budiao"] = "不凋之花",
    [":ev__budiao"] = "锁定技，当你受到伤害时，若此伤害有/无来源，伤害来源/你选择你的一张手牌，展示之：若此牌为你点数最小的手牌，你失去1点体力；否则你防止此伤害。",
    ["#ev__budiao-show"] = "不凋之花：请展示一张手牌",
  }

local Caesar = General(extension, "ev__caesar", "ev", 4)

local shandong_get = fk.CreateViewAsSkill{
  name = "ev__shandong&",
  anim_type = "offensive",
  pattern = "slash",
  expand_pile = function()
    if Self:getMark("caikuang-turn") == 0 and #Self:getTableMark("ev__caikuang") ~= 0 then
      return Self:getTableMark("ev__caikuang")
    else
      return {}
    end
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Red
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}

local shandong_lose = fk.CreateTriggerSkill{
  name = "#shandong_lose",
  mute = true,
  refresh_events = {fk.TurnStart, fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      player.room:addPlayerMark(player, "shandong-turn")
    else
      if player:getMark("shandong-turn") > 0 then
        player.room:handleAddLoseSkills(player, "-ev__shandong&")
      end
    end
  end,
}

local shandong_prohibit = fk.CreateProhibitSkill{
  name = "#shandong_prohibit",
  prohibit_use = function(self, player, card)
    return player:hasSkill(self) and card and card.color == Card.Red and Fk:currentRoom():getCardArea(card) == Card.PlayerHand and not card:isVirtual()
  end,
}

local ev__shandong = fk.CreateActiveSkill{
  name = "ev__shandong",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):getMark("@@ev__shandong-turn") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    --room:setPlayerMark(target, "@@ev__shandong")
    local mark = player:getTableMark("ev__shandong")
    table.insertIfNeed(mark, effect.tos[1])
    room:setPlayerMark(player, "ev__shandong", mark)
    room:handleAddLoseSkills(target, "ev__shandong&")
  end,
}

local shandong_buff = fk.CreateTriggerSkill{
  name = "#shandong_buff",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target:hasSkill("ev__shandong&") and data.card.trueName == "slash" and data.card.color == Card.Red
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, "ev__shandong")
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and #player:getTableMark("ev__shandong") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, id in ipairs(player:getTableMark("ev__shandong")) do
      local p = room:getPlayerById(id)
      if p:isAlive() then
        room:addPlayerMark(p, "@@ev__shandong-turn")
      end
    end
    room:setPlayerMark(player, "ev__shandong", 0)
  end,
}

local ev__huangzisi = fk.CreateActiveSkill{
  name = "ev__huangzisi",
  frequency = Skill.Limited,
  prompt = "你可选择一张武器牌使用",
  card_num = 1,
  target_num = 0,
  card_filter = function(self, to_select, selected)
    local card = Fk:getCardById(to_select)
    local canUse = Self:canUse(card) and not Self:prohibitUse(card)
    return card.sub_type == Card.SubtypeWeapon and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand and canUse
  end,
  target_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:useCard({
      from = effect.from,
      tos = {{effect.from}},
      card = Fk:getCardById(effect.cards[1]),
    })
    local targets = table.map(table.filter(room:getOtherPlayers(player), function(p) return player:inMyAttackRange(p) end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#ev__huangzisi-choose", self.name, true)
    if #tos > 0 then
      local target = room:getPlayerById(tos[1])
      local invoke = target:isAlive()
      while invoke do
        if target.dead then invoke = false break end
        local judge = {
          who = player,
          reason = self.name,
          pattern = ".",
        }
        room:judge(judge)
        local cards = table.filter(player:getCardIds("he"), function (id) return Fk:getCardById(id).color == judge.card.color end)
        local card = room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = cards }), "#huangzisi::"..target.id)
        if #card > 0 then
          room:useVirtualCard("ev__slash", card, player, target, self.name, true, true, true)
        else
          invoke = false
          break
        end
      end
    end
  end
}

shandong_get:addRelatedSkill(shandong_lose)
shandong_get:addRelatedSkill(shandong_prohibit)
ev__shandong:addRelatedSkill(shandong_buff)
Fk:addSkill(shandong_get)
Caesar:addSkill(ev__shandong)
Caesar:addSkill(ev__huangzisi)

Fk:loadTranslationTable{
  ["ev__caesar"] = "恺撒",
  ["designer:ev__caesar"] = "KINGDOM43",
  ["ev__shandong"] = "煽动",
  [":ev__shandong"] = "阶段技，你可选择一名角色（不得为上回合此技能的目标），则直至其下回合结束：其不能使用非转化的红色手牌，其可将一张红色牌当【杀】使用，且当其使用红色【杀】时，你摸一张牌。",
  ["@@ev__shandong-turn"] = "煽动",
  ["ev__shandong&"] = "煽动",
  ["#shandong_prohibit"] = "煽动",
  [":ev__shandong&"] = "你不能使用非转化的红色手牌，你可将一张红色牌当【杀】使用，回合结束后，你失去此技能。",

  ["#jifengnutao-choose"] = "你可以为%arg额外增加任意个目标",
  ["ev__huangzisi"] = "黄之死",
  [":ev__huangzisi"] = "限定技，出牌阶段，你可使用一张武器牌，选择你攻击范围内的一名角色，然后{你判定，将一张与结果颜色相同的牌当【杀】对其使用}。你可重复{ }里的流程直至放弃使用【杀】。",
  ["#ev__huangzisi-choose"] = "请选择你攻击范围内的一名角色",
  ["#huangzisi"] = "你可以将一张与结果颜色相同的牌当【杀】对%dest使用",
}

local Kuroba = General(extension, "ev__kuroba", "ev", 4)

local daoxingyugao = fk.CreateActiveSkill{
  name = "daoxingyugao",
  anim_type = "control",
  prompt = "请选择一张手牌和一名装备区内有牌的角色",
  target_num = 1,
  card_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select):getMark("@@shown-inhand") == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, to_select, selected)
    if #selected == 0 then
      return #Fk:currentRoom():getPlayerById(to_select):getCardIds("e") > 0
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    EV.OpenCards(room, player, effect.cards[1], self.name)
    local id = room:askForCardChosen(player, to, "e", self.name)
    room:setPlayerMark(player, "@$daoxingyugao", {id})
    room:setPlayerMark(player, "daoxingyugao_target", to.id)
  end,
}

local daoxingyugao_trigger = fk.CreateTriggerSkill{
  name = "#daoxingyugao_trigger",
  anim_type = "control",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target:getMark("daoxingyugao-turn") > 0 and player:hasSkill(self) and player:getMark("@$daoxingyugao") ~= 0
    and player:getMark("daoxingyugao_target") == target.id then
      return #player.room.logic:getEventsOfScope(GameEvent.Damage, 1, function (e)
        local damage = e.data[1]
        if damage and target == damage.from and player == damage.to then
          return true
        end
      end, Player.HistoryTurn) == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local id = player:getMark("@$daoxingyugao")[1]
    if room:getCardOwner(id) == target then
      room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true)
    end
  end,

  refresh_events = {fk.TurnStart, fk.AfterTurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and player:getMark("@$daoxingyugao") ~= 0 and player:getMark("daoxingyugao_target") == target.id
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      player.room:addPlayerMark(target, "daoxingyugao-turn")
    else
      if target:getMark("daoxingyugao-turn") > 0 then
        player.room:setPlayerMark(player, "daoxingyugao_target", 0)
        player.room:setPlayerMark(player, "@$daoxingyugao", 0)
      end
    end
  end,
}

local moshushihuo = fk.CreateTriggerSkill{
  name = "moshushihuo",
  anim_type = "defensive",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
    local cards = {}
    if player:getMark("moshushihuo_fix") == 0 then 
      local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      cards = player.room:askForCard(player, 1, 1, false, self.name, true, tostring(Exppattern{ id = unshown }), "#moshushihuo")
    else
      local shown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
      cards = player.room:askForCard(player, 1, 999, false, self.name, true, tostring(Exppattern{ id = shown }), "#moshushihuo-fix")
    end
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("moshushihuo_fix") == 0 then 
      EV.OpenCards(room, player, self.cost_data, self.name)
      if table.every(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end) then
        room:addPlayerMark(player, "moshushihuo-turn")
        room:addPlayerMark(player, "moshushihuo_fix")
      end
    else
      EV.ConcealCards(room, player, self.cost_data, self.name)
      if table.every(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end) then
        room:addPlayerMark(player, "moshushihuo-turn")
      end
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("moshushihuo_fix") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "moshushihuo_fix", 0)
  end,
}

local moshushihuo_prohibit = fk.CreateProhibitSkill{
  name = "#moshushihuo_prohibit",
  is_prohibited = function(self, from, to, card)
    return card.trueName == "slash" and to:hasSkill(self) and to:getMark("moshushihuo-turn") > 0
  end,
}

daoxingyugao:addRelatedSkill(daoxingyugao_trigger)
moshushihuo:addRelatedSkill(moshushihuo_prohibit)
Kuroba:addSkill(daoxingyugao)
Kuroba:addSkill(moshushihuo)

Fk:loadTranslationTable{
  ["ev__kuroba"] = "怪盗基德",
  ["designer:ev__kuroba"] = "zengyouyu+KINGDOM43",
  ["daoxingyugao"] = "盗行预告",
  ["#daoxingyugao_trigger"] = "盗行预告",
  ["@$daoxingyugao"] = "盗行预告",
  [":daoxingyugao"] = "阶段技，你可明置一张手牌并选择一名角色装备区里的一张牌；其下回合结束时，若其于此回合内未对你造成过伤害，你获得其装备区里的此牌。",
  ["moshushihuo"] = "魔术视惑",
  [":moshushihuo"] = "其他角色的回合开始时，你可明置一张手牌；然后若你的所有手牌均已明置，则你于此回合内不是【杀】的合法目标，且你将“明置”改为“暗置”，“一”改为“任意”直至你的下回合开始。",
  ["#moshushihuo"] = "你可明置一张手牌",
  ["#moshushihuo-fix"] = "你可暗置至少一张手牌",
  ["#moshushihuo_prohibit"] = "魔术视惑",
}

local Patchouli = General(extension, "ev__patchouli", "ev", 3, 3, General.Female)
local ev__qiyao = fk.CreateViewAsSkill{
  name = "ev__qiyao",
  pattern = ".|.|.|.|.|trick|.",
  prompt = "#ev__qiyao",
  interaction = function()
    local all_names = U.getAllCardNames("t")
    local names = U.getViewAsCardNames(Self, "ev__qiyao", all_names, {}, Self:getTableMark("ev__qiyao-turn"))
    if #names == 0 then return false end
    return U.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  view_as = function(self, cards)
    local n = Self:usedSkillTimes(self.name, Player.HistoryPhase) + 1
    if #cards ~= n or not self.interaction.data then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng()
  end,
  enabled_at_response = function(self, player, response)
    return false
  end,
}

local qiyao_trigger = fk.CreateTriggerSkill{
  name = "#qiyao_trigger",
  mute = true,
  refresh_events = {fk.CardUsing, fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card:isCommonTrick()
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      local mark = player:getTableMark("ev__qiyao-turn")
      table.insert(mark, data.card.trueName)
      room:setPlayerMark(player, "ev__qiyao-turn", mark)
    else
      if data.card.skillName == "ev__qiyao" then
        if player:usedSkillTimes("ev__qiyao", Player.HistoryPhase) > 1 and
        #TargetGroup:getRealTargets(data.tos) > player:usedSkillTimes("ev__qiyao", Player.HistoryPhase) then
          room:loseHp(player, 1, "ev__qiyao")
        end
      end
    end
  end,
}

ev__qiyao:addRelatedSkill(qiyao_trigger)
Patchouli:addSkill(ev__qiyao)

local ev__riyin_trigger = fk.CreateTriggerSkill{
  name = "#ev__riyin_trigger",
  refresh_events = {fk.HandleAskForPlayCard, fk.PreCardEffect},
  can_refresh = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return player:hasSkill("ev__riyin") and data.card.type == Card.TypeTrick and player.phase == Player.NotActive
    else
      return data.eventData and data.eventData.from == player.id and data.eventData.card and data.eventData.card.type == Card.TypeTrick
      and player.phase ~= Player.NotActive and player:hasSkill("ev__riyin")
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.PreCardEffect then
      room:setPlayerMark(player, "ev__riyin_record", {data.card:getSuitString()})
    else
      if not data.afterRequest then
        room:setBanner("ev__riyin_record", data.eventData.card:getSuitString())
      else
        room:setBanner("ev__riyin_record", 0)
      end
    end
  end,
}

local ev__riyin = fk.CreateViewAsSkill{
  name = "ev__riyin",
  pattern = "nullification",
  card_filter = function(self, to_select, selected)
    local suit = Self:getMark("ev__riyin_record")
    if type(suit) == "table" then
      suit = suit[1]
    else
      return false
    end
    return #selected == 0 and Fk:getCardById(to_select):getSuitString() ~= suit
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("ev__nullification")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    return player.phase == Player.NotActive
  end,
  before_use = function(self, player)
    player.room:setPlayerMark(player, "ev__riyin_record", 0)
  end,
}

local ev__riyin_prohibit = fk.CreateProhibitSkill{
  name = "#ev__riyin_prohibit",
  prohibit_use = function(self, player, card)
    local room = Fk:currentRoom()
    local suit = room:getBanner("ev__riyin_record")
    if suit and suit ~= 0 then
       return card and card.name == "ev__nullification" and card:getSuitString() ~= suit
    end
  end,
}

ev__riyin:addRelatedSkill(ev__riyin_trigger)
ev__riyin:addRelatedSkill(ev__riyin_prohibit)
Patchouli:addSkill(ev__riyin)

Fk:loadTranslationTable{
  ["ev__patchouli"] = "帕秋莉",
  ["designer:ev__patchouli"] = "夜之礼赞",
  ["ev__qiyao"] = "七曜",
  [":ev__qiyao"] = "出牌阶段，你可将X+1张手牌当你于本回合内未使用过的即时魔法牌使用；当此牌结算结束后，若X大于1且此牌指定的目标数大于X，你失去1点体力（X为你于本阶段内发动过此技能的次数）。",
  ["#ev__qiyao"] = "你可将X+1张手牌当时魔法牌使用，X为此阶段此技能发动次数",
  ["ev__riyin"] = "日阴",
  [":ev__riyin"] = "你的回合内，你使用的魔法牌不是与之花色不同的【魔法禁令】的合法目标。你的回合外，你可将与目标魔法牌花色不同的一张牌当【魔法禁令】使用。",
  ["#ev__riyin_prohibit"] = "日阴",
}

local Saber = General(extension, "ev__saber", "ev", 4, 4, General.Female)

local ev__fengwang = fk.CreateTriggerSkill{
  name = "ev__fengwang",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
    and #table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local choice = room:askForChoice(to, {"spade", "heart", "club", "diamond"}, self.name)
    local id = room:askForCardChosen(to, player, 'h', self.name)
    EV.choicelog(to, choice)
    EV.OpenCards(room, player, id, self.name, to)
    if Fk:getCardById(id):getSuitString() ~= choice and to:isAlive() then
      data.disresponsive = true
    end
  end,
}
Saber:addSkill(ev__fengwang)

local ev__shiyue_choose = fk.CreateActiveSkill{
  name = "ev__shiyue_choose",
  card_num = 0,
  min_target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, _, _, _, from)
    local player = Fk:currentRoom():getPlayerById(from:getMark("shiyue_target"))
    if to_select == from:getMark("shiyue_target") or to_select == from.id then return false end
    local target = Fk:currentRoom():getPlayerById(to_select)
    if #selected == 0 then
      return target:getNextAlive() == player or player:getNextAlive() == target
    else
      if table.contains(selected, player:getNextAlive().id) then
        if Fk:currentRoom():getPlayerById(selected[#selected]):getNextAlive() == target then
          return true
        end
      end
      if Fk:currentRoom():getPlayerById(selected[1]):getNextAlive() == player then
        if target:getNextAlive().id == selected[#selected] then
          return true
        end
      end
    end
  end,
  feasible = function(self, selected, selected_cards)
    if #selected > 0 then
      local player = Fk:currentRoom():getPlayerById(Self:getMark("shiyue_target"))
      local p1 = Fk:currentRoom():getPlayerById(selected[1])
      if not (p1:getNextAlive() == player or player:getNextAlive() == p1) then return false end
      if #selected == 1 then return true end
      if p1:getNextAlive() == player then
        for i = 1, #selected - 1, 1 do
          if Fk:currentRoom():getPlayerById(selected[i+1]):getNextAlive() ~= Fk:currentRoom():getPlayerById(selected[i]) then
            return false
          end
        end
        return #selected <= Self:getMark("@shiyue-turn")
      end
      if player:getNextAlive() == p1 then
        for i = 1, #selected - 1, 1 do
          if Fk:currentRoom():getPlayerById(selected[i]):getNextAlive() ~= Fk:currentRoom():getPlayerById(selected[i+1]) then
            return false
          end
        end
        return #selected <= Self:getMark("@shiyue-turn")
      end
    end
  end,
}

Fk:addSkill(ev__shiyue_choose)

local ev__shiyue = fk.CreateTriggerSkill{
  name = "ev__shiyue",
  mute = true,
  events = {fk.EventPhaseStart, fk.TargetSpecifying},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play or (player.phase == Player.Finish and player:getMark("@shiyue-turn") > 0)
      else
        return target == player and player:getMark("@shiyue-turn") > 0 and data.card.trueName == "slash" and #U.getUseExtraTargets(player.room, data, true, true) > 0
        and data.tos and #AimGroup:getAllTargets(data.tos) == 1
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      if player.phase == Player.Play then
        return room:askForSkillInvoke(player, self.name, nil, "#ev__shiyue-invoke")
      else
        return true
      end
    else
      room:setPlayerMark(player, "shiyue_target", AimGroup:getAllTargets(data.tos)[1])
      local _, dat = room:askForUseActiveSkill(player, "ev__shiyue_choose", "#ev__shiyue-choose:::"..player:getMark("@shiyue-turn"), true)
      room:setPlayerMark(player, "shiyue_target",0)
      if dat then
        self.cost_data = dat.targets
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      if player.phase == Player.Play then
        local numbers = {}
        for _, p in ipairs(room.alive_players) do
          if not p:isKongcheng() then
            for _, id in ipairs(p:getCardIds(Player.Hand)) do
              if Fk:getCardById(id):getMark("@@shown-inhand") ~= 0 then
                table.insertIfNeed(numbers, Fk:getCardById(id).number)
              end
            end
          end
        end
        if #numbers > 0 then
          player:drawCards(#numbers, self.name)
          room:setPlayerMark(player, "@shiyue-turn", #numbers)
          room:notifySkillInvoked(player, self.name, "big")
        end
        local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
        EV.OpenCards(room, player, unshown, self.name)
      elseif player.phase == Player.Finish then
        local n = 0
        U.getActualDamageEvents(player.room, 999, function(e)
          local damage = e.data[1]
          if damage.from == player then
            n = n + damage.damage
          end
        end)
        if n < player:getMark("@shiyue-turn") then
          room:askForDiscard(player, player:getMark("@shiyue-turn"), player:getMark("@shiyue-turn"), true, self.name, false)
        end
      end
    else
      for _, pid in ipairs(self.cost_data) do
        AimGroup:addTargets(room, data, pid)
      end
      room:sendLog{
        type = "#AddTargetsBySkill",
        from = player.id,
        to = self.cost_data,
        arg = self.name,
        arg2 = data.card:toLogString(),
        toast = true,
      }
    end
  end,
}

Saber:addSkill(ev__shiyue)

Fk:loadTranslationTable{
  ["ev__saber"] = "阿尔托莉雅",
  ["designer:ev__saber"] = "夜之礼赞",
  ["ev__fengwang"] = "风王结界",
  [":ev__fengwang"] = "当你使用【杀】指定一个目标后，你可令其选择一种花色并明置你的一张手牌，若此牌的花色与其选择的不同，此【杀】不是【闪】的合法目标。",
  ["ev__shiyue"] = "誓约之剑",
  [":ev__shiyue"] = "出牌阶段开始时，你可摸等同于所有角色的明置手牌的点数种类的牌，然后明置所有手牌；若如此做，当你于本回合内使用【杀】指定一个目标时，可额外选择与其连续相邻的至多X名其他角色为目标。结束阶段，若你于本回合内造成过的伤害数小于X，你弃置X张牌（X为你以此法摸的牌数）。",
  ["#ev__shiyue-invoke"] = "你可以发动誓约胜利之剑",
  ["@shiyue-turn"] = "誓约胜利",
  ["#ev__shiyue-choose"] = "你可以增加目标连续相邻的至多%arg名其他角色",
}

local Eirin = General(extension, "ev__eirin", "ev", 3, 3, General.Female)

local ev__mizang = fk.CreateTriggerSkill{
  name = "ev__mizang",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
      return #table.filter(player.room.alive_players, function(p) return p:inMyAttackRange(target) end) >= target.hp
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = math.min(target.maxHp, 4) * 2
    local card_ids = room:getNCards(n, "bottom")
    local to_throw = room:askForCardsChosen(player, player, 0, n, {
      card_data = {
        { "Bottom", card_ids }
      }
    }, self.name, "#ev__mizang-throw")
    if #to_throw > 0 then
      for _, id in ipairs(to_throw) do
        table.removeOne(card_ids, id)
      end
      room:moveCardTo(to_throw, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "", true)
    end
    if #card_ids > 0 then
      room:askForGuanxing(player, card_ids)
    end
  end,
}

local ev__susheng = fk.CreateTriggerSkill{
  name = "ev__susheng",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and (target == player or #target:getCardIds("he") > 0)
  end,
  on_cost = function(self, event, target, player, data)
    if target == player then
      return player.room:askForSkillInvoke(player, self.name)
    else
      return player.room:askForSkillInvoke(target, self.name, data, "#ev__susheng-invoke::"..player.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    if target == player then
      player:drawCards(1, self.name, "bottom")
      n = 1
    else
      local cards = room:askForCardsChosen(player, target, 1, #target:getCardIds("he"), "he", self.name)
      room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      n = #cards
    end
    local to_throw = room:askForDiscard(player, n, 999, true, self.name, false, ".", "#ev__susheng-discard:::"..n, true)
    room:moveCardTo(to_throw, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    if target == player then
      local colors = {}
      for _, id in ipairs(to_throw) do
        table.insertIfNeed(colors, Fk:getCardById(id).color)
      end
      if #colors == 2 then 
        room:recover({
          who = player,
          num = 1 - player.hp,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
    if target ~= player and EV.countSuits(to_throw) == 4 then
      room:recover({
        who = target,
        num = target.maxHp - target.hp,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}

Eirin:addSkill(ev__mizang)
Eirin:addSkill(ev__susheng)

Fk:loadTranslationTable{
  ["ev__eirin"] = "八意永琳",
  ["designer:ev__eirin"] = "KINGDOM43",
  ["ev__mizang"] = "<font color=\"#D2042D\">密</font><font color=\"#1F51FF\">葬</font>",
  [":ev__mizang"] = "轮次技，一名角色的回合结束时，若攻击范围内含有其的角色数不小于其体力值，你可观看牌堆底的2X张牌，将其中的任意张牌置入弃牌堆，然后你将其中的任意张牌置于牌堆顶（X为其体力上限且至多为4）。",
  ["#ev__mizang-throw"] = "请选择任意张牌置入弃牌堆",
  ["ev__susheng"] = "<font color=\"#D2042D\">苏</font><font color=\"#1F51FF\">生</font>",
  [":ev__susheng"] = "当一名角色进入濒死状态时，若其：<font color=\"#D2042D\">为你</font>/<font color=\"#1F51FF\">不为你</font>，"..
  "<font color=\"#D2042D\">你可从牌堆底摸一张牌</font>/<font color=\"#1F51FF\">其可令你选择其任意张牌并获得之</font>，"..
  "然后你弃置至少等量张牌，若其中含有所有<font color=\"#D2042D\">颜色</font>/<font color=\"#1F51FF\">花色</font>，"..
  "<font color=\"#D2042D\">你</font>/<font color=\"#1F51FF\">其</font>将体力回复至<font color=\"#D2042D\">1点</font>/<font color=\"#1F51FF\">体力上限</font>。",
  ["#ev__susheng-invoke"] = "你可以令%dest选择你任意张牌获得之",
  ["#ev__susheng-discard"] = "请弃置至少%arg张牌",
}

local Shirai = General(extension, "ev__shirai", "ev", 3, 3, General.Female)

local kongjianlidong = fk.CreateActiveSkill{
  name = "kongjianlidong",
  anim_type = "offensive",
  prompt = "请选择一名装备区内有牌的角色和另一名角色",
  target_num = 2,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, _, _, _, player)
    if #selected == 0 then
      return #Fk:currentRoom():getPlayerById(to_select):getCardIds("e") > 0 and player:distanceTo(Fk:currentRoom():getPlayerById(to_select)) <= 1
    else
      return #selected < 2
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local target = room:getPlayerById(effect.tos[2])
    local id = room:askForCardChosen(player, to, "e", self.name)
    local choice = room:askForChoice(player, {"$Hand","$Equip"}, self.name)
    if choice == "$Hand" then
      room:moveCardTo(id, Card.PlayerHand, target, fk.ReasonJustMove, self.name, "", true)
      if Fk:getCardById(id).sub_type == Card.SubtypeWeapon and room:askForSkillInvoke(player, self.name, nil, "#kongjianlidong:"..target.id) then
        room:damage({
          from = player,
          to = target,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    else
      U.moveCardIntoEquip(room, target, id, self.name, true, player)
    end
  end,
}

local ev__shunshen = fk.CreateDistanceSkill{
  name = "ev__shunshen",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) and from:getHandcardNum() > from.hp then
      return from.hp - from:getHandcardNum()
    end
    if to:hasSkill(self) and to.hp > to:getHandcardNum() then
      return to.hp - to:getHandcardNum() 
    end
  end,
}

Shirai:addSkill(kongjianlidong)
Shirai:addSkill(ev__shunshen)

Fk:loadTranslationTable{
  ["ev__shirai"] = "白井黑子",
  ["designer:ev__shirai"] = "zengyouyu",
  ["illustrator:ev__shirai"] = "Ensinn",
  ["kongjianlidong"] = "空间移动",
  [":kongjianlidong"] = "阶段技，你可选择距离1以内的一名角色，将其装备区里的一张牌置入另一名角色的装备区（替换原装备）或手牌区；若你以此法将武器牌置入一名角色的手牌区，你可对其造成1点伤害。",
  ["#kongjianlidong"] = "你可以对%src造成1点伤害",
  ["ev__shunshen"] = "瞬身",
  [":ev__shunshen"] = "锁定技，若你的手牌数大于/小于体力值，你与其他角色的距离-X/其他角色与你的距离+X（X为你的体力值与手牌数之差）。",
}

local Voldemort = General(extension, "ev__voldemort", "ev", 4)

local ev__suoming = fk.CreateTriggerSkill{
  name = "ev__suoming",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target:isAlive() and player:inMyAttackRange(target)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1, self.name)
    room:loseHp(target, 1, self.name)
  end,
}

local ev__hunqi = fk.CreateTriggerSkill{
  name = "ev__hunqi",
  events = {fk.DamageInflicted, fk.PreHpLost, fk.BeforeMaxHpChanged},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and #player:getCardIds("e") > 0 then
      if event == fk.BeforeMaxHpChanged then
        return player.maxHp == 1 and data.num < 0
      else
        return player.hp == 1
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    for _, slot in ipairs(player:getAvailableEquipSlots()) do
      if slot == Player.OffensiveRideSlot or slot == Player.DefensiveRideSlot then
        table.insertIfNeed(choices, "RideSlot")
      else
        table.insert(choices, slot)
      end
    end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name)
    if choice == "RideSlot" then
      choice = {Player.OffensiveRideSlot, Player.DefensiveRideSlot}
    end
    room:abortPlayerArea(player, choice)
    return true
  end,
}

local ev__jinyan = fk.CreateTriggerSkill{
  name = "ev__jinyan",
  events = {fk.TargetSpecified},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return data.to == player.id and data.from ~= player.id and player:hasSkill(self)
    and player:inMyAttackRange(player.room:getPlayerById(data.from)) and data.card.type == Card.TypeBasic
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room:askForDiscard(room:getPlayerById(data.from), 1, 1, true, self.name, true, ".", "#ev__jinyan-discard:"..player.id) == 0 then
      table.insertIfNeed(data.nullifiedTargets, player.id)
    end
  end,
}

Voldemort:addSkill(ev__suoming)
Voldemort:addSkill(ev__hunqi)
Voldemort:addSkill(ev__jinyan)

Fk:loadTranslationTable{
  ["ev__voldemort"] = "伏地魔",
  ["designer:ev__voldemort"] = "潜水员最棒",
  ["ev__suoming"] = "索命",
  [":ev__suoming"] = "当你攻击范围内的一名角色受到伤害后，你可减少1点体力上限，令其失去1点体力。",
  ["ev__hunqi"] = "魂器",
  [":ev__hunqi"] = "锁定技，当你受到伤害时或失去体力时/减体力上限前，若你的装备区里有牌，且你的体力值/体力上限为1，则你废除一个装备栏，防止之。",
  ["ev__jinyan"] = "噤言",
  [":ev__jinyan"] = "锁定技，其他角色使用基础牌指定你为目标后，若其在你的攻击范围内，其选择一项：1.弃置一张牌；2.令此牌对你无效。",
  ["#ev__jinyan-discard"] = "噤言：请弃置一张牌，否则此牌对%src无效",
}

local Widowmaker = General(extension, "ev__widowmaker", "ev", 3, 3, General.Female)

local heibaihezhiwen = fk.CreateTriggerSkill{
  name = "heibaihezhiwen",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and not player.room:getPlayerById(data.to):isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local unshown = table.filter(to:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    local id = table.random(unshown, 1)[1]
    if #id > 0 then
      to:showCards({id})
      if Fk:getCardById(id).trueName ~= "jink" then
        data.disresponsive = true
      end
      if Fk:getCardById(id).suit == data.card.suit then
        data.additionalDamage = (data.additionalDamage or 0) + 1
      end
    end
  end,
}

local ev__gousuo = fk.CreateTriggerSkill{
  name = "ev__gousuo",
  events = {fk.AskForCardUse},
  --mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target == player and data.cardName == "jink"
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getAlivePlayers(), function(p)
    return table.find(p:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end) end)
    targets = table.map(targets, Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#ev__gousuo-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local unshown = table.filter(to:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    local id = table.random(unshown, 1)
    if #id > 0 then
      EV.OpenCards(room, to, id, self.name)
      if Fk:getCardById(id[1]).trueName == "jink" then
        data.result = {
          from = player.id,
          card = Fk:cloneCard(data.cardName),
        }
        data.result.card.skillName = self.name
        if data.eventData then
          data.result.toCard = data.eventData.toCard
          data.result.responseToEvent = data.eventData.responseToEvent
        end
        return true
      end
    end
  end
}

local ev__gousuo_tar = fk.CreateTargetModSkill{
  name = "#ev__gousuo_tar",
  bypass_distances = function(self, player, skill, card, to)
    if card and card.trueName == "slash" and player:hasSkill(self) and to then
      return to:getMark("@$shown") == 0
    end
  end,
}

local zhizhuguilei = fk.CreateTriggerSkill{
  name = "zhizhuguilei",
  anim_type = "control",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.id ~= data.from
    and table.find(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = room:getPlayerById(data.from)
    local unshown = table.filter(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    local card = table.random(unshown, 1)
    if #card > 0 then
      local id = card[1]
      player:showCards(card)
      if Fk:getCardById(id).color == Card.Black then
        if not player:isBuddy(from) then
          local mark = player:getTableMark("zhizhuguilei")
          table.insertIfNeed(mark, data.from)
          room:setPlayerMark(player, "zhizhuguilei", mark)
          player:addBuddy(from)
          room:addPlayerMark(from, "@!guilei")
        end
      end
    end
  end,

  refresh_events = {fk.TurnStart, fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("zhizhuguilei") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:addPlayerMark(player, "zhizhuguilei-turn")
    else
      if player:getMark("zhizhuguilei-turn") > 0 then
        for _, p in ipairs(room:getOtherPlayers(player)) do
          local mark = player:getTableMark("zhizhuguilei")
          if table.contains(mark, p.id) then
            player:removeBuddy(p)
            room:setPlayerMark(p, "@!guilei", 0)
          end
        end
      end
    end
  end,
}

ev__gousuo:addRelatedSkill(ev__gousuo_tar)
Widowmaker:addSkill(heibaihezhiwen)
Widowmaker:addSkill(ev__gousuo)
Widowmaker:addSkill(zhizhuguilei)

Fk:loadTranslationTable{
  ["ev__widowmaker"] = "黑百合",
  ["designer:ev__widowmaker"] = "zengyouyu",
  ["illustrator:ev__widowmaker"] = "梁星",
  ["heibaihezhiwen"] = "黑百合之吻",
  [":heibaihezhiwen"] = "锁定技，当你使用【杀】指定一个目标后，你展示其一张手牌，若此牌：不为【闪】，此【杀】不是【闪】的合法目标；花色与此【杀】相同，此【杀】伤害+1。",
  ["ev__gousuo"] = "钩索",
  [":ev__gousuo"] = "你对没有明置手牌的角色使用【杀】无距离限制。当你需要使用【闪】时，你可明置一名角色的一张手牌，若为【闪】，你视为使用之。",
  ["#ev__gousuo-choose"] = "钩索：你可明置一名角色的一张手牌",
  ["zhizhuguilei"] = "蜘蛛诡雷",
  [":zhizhuguilei"] = "当你成为其他角色使用牌的目标后，你可令其展示你的一张手牌，若此牌为黑色牌，则直至你的下回合结束，其所有手牌均对你可见。",
}

local heiyansheshou = General(extension, "ev__heiyansheshou", "ev", 4, 4, General.Female)

local ev__jueduiyazhi = fk.CreateTriggerSkill{
  name = "ev__jueduiyazhi",
  anim_type = "offensive",
  events = {fk.TargetSpecified, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return target == player and player:hasSkill(self) and data.card.trueName == "slash" and not player.room:getPlayerById(data.to):isNude()
    else
      return player:hasSkill(self.name, true, true) and
       #table.filter(player.room.alive_players, function(p) return p:getMark("jueduiyazhi-turn") > 0 end) > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return player.room:askForSkillInvoke(player, self.name)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local to = room:getPlayerById(data.to)
      --local cards = room:askForCardsChosen(player, to, 0, to.hp, "he", self.name)
      local cards = room:askForCardsChosen(player, to, 0, to.hp, "he", self.name)
      if #cards > 0 then
        room:addPlayerMark(to, "jueduiyazhi-turn", #cards)
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      end
    else
      for _, p in ipairs(room:getAlivePlayers()) do
        if p:getMark("jueduiyazhi-turn") > 0 then
          p:drawCards(p:getMark("jueduiyazhi-turn"), self.name)
          room:setPlayerMark(p, "jueduiyazhi-turn", 0)
        end
      end
    end
  end,
}

local gattlingmode_attackrange = fk.CreateAttackRangeSkill{
  name = "#gattlingmode_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("ev__gattlingmode") then
      return #from:getCardIds(Player.Equip)
    end
  end,
}

local ev__gattlingmode = fk.CreateTriggerSkill{
  name = "ev__gattlingmode",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and not data.to.dead
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, true, self.name, true, ".|.|spade", "#ev__gattlingmode::"..data.to.id)
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:useVirtualCard("ev__slash", self.cost_data, player, data.to, self.name, false)
  end,
}

ev__gattlingmode:addRelatedSkill(gattlingmode_attackrange)
heiyansheshou:addSkill(ev__jueduiyazhi)
heiyansheshou:addSkill(ev__gattlingmode)

Fk:loadTranslationTable{
  ["ev__heiyansheshou"] = "黑岩射手",
  ["designer:ev__heiyansheshou"] = "小樱",
  ["ev__jueduiyazhi"] = "绝对压制",
  [":ev__jueduiyazhi"] = "当你使用【杀】指定一个目标后，你可弃置其至多等同于其体力值张牌；若如此做，其于当前回合结束时摸等量张牌。",
  ["ev__gattlingmode"] = "机枪模式",
  [":ev__gattlingmode"] = "你的攻击范围+X（X为你装备区里的牌数）。当你使用【杀】对目标角色造成伤害后，你可将一张黑桃牌当【杀】对其使用。",
  ["#ev__gattlingmode"] = "你可将一张黑桃牌当【杀】对%dest使用",
}

local lufei = General(extension, "ev__lufei", "ev", 4)

local xiangjiaoguoshi = fk.CreateTriggerSkill{
  name = "xiangjiaoguoshi",
  mute = true,
  events = {fk.EventPhaseStart, fk.DamageInflicted},
  derived_piles = {"rubber"},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play and #player:getPile("rubber") <= player.maxHp
      else
        return data.damageType == fk.ThunderDamage
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local cards = player.room:askForCard(player, 1, 999, false, self.name, true, ".", "#xiangjiaoguoshi-put")
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      player:addToPile("rubber", self.cost_data, true, self.name)
    else
      player.room:notifySkillInvoked(player, self.name, "defensive")
      return true
    end
  end,
}

local xiangjiaoguoshi_attackrange = fk.CreateAttackRangeSkill{
  name = "#xiangjiaoguoshi_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill(self) then
      return #from:getPile("rubber")
    end
  end,
}

local xiangjiaoshensuo = fk.CreateTriggerSkill{
  name = "xiangjiaoshensuo",
  --anim_type = "defensive",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  derived_piles = {"rubber"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
    and player.room:getPlayerById(data.from):getEquipment(Card.SubtypeWeapon) == nil
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForCard(player, 1, 2, false, self.name, true, ".|.|.|rubber|.|.", "#xiangjiaoshensuo-invoke", "rubber")
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:moveCardTo(self.cost_data, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
    if #self.cost_data == 1 then
      room:getPlayerById(data.from):addCardUseHistory("slash", -1)
    else
      local choice = room:askForChoice(player, {"xiangjiaoshensuo1", "xiangjiaoshensuo2"}, self.name)
      if choice == "xiangjiaoshensuo1" then
        data.additionalDamage = (data.additionalDamage or 0) + 1
      else
        data.extra_data = data.extra_data or {}
        data.extra_data.xiangjiaoshensuo = data.to
      end
    end
  end,

  refresh_events = {fk.DamageInflicted},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
      return e and e.data[1].extra_data and e.data[1].extra_data.xiangjiaoshensuo
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if not e then return end
    local use = e.data[1]
    if use.extra_data.xiangjiaoshensuo == data.to.id then
      data.damage = data.damage - 1
    end
  end,
}

xiangjiaoguoshi:addRelatedSkill(xiangjiaoguoshi_attackrange)
lufei:addSkill(xiangjiaoguoshi)
lufei:addSkill(xiangjiaoshensuo)

Fk:loadTranslationTable{
  ["ev__lufei"] = "路飞",
  ["designer:ev__lufei"] = "KINGDOM43",
  ["rubber"] = "胶",
  ["xiangjiaoguoshi"] = "橡胶果实",
  ["#xiangjiaoguoshi-put"] = "你可将任意张手牌置于角色牌上",
  [":xiangjiaoguoshi"] = "当你受到雷电伤害时，你防止之。出牌阶段开始时，若你的角色牌上的牌数不大于体力上限，你可将任意张手牌置于角色牌上，称为“胶”；你的攻击范围+X（X为“胶”数）。",
  ["xiangjiaoshensuo"] = "橡胶伸缩",
  [":xiangjiaoshensuo"] = "当你指定或成为【杀】的目标后，若此【杀】的使用者的装备区里没有武器牌，你可获得一张/两张“胶”，令此【杀】不计入次数限制/伤害+1或-1。",
  ["#xiangjiaoshensuo-invoke"] = "你可获得一至两张“胶”",
  ["xiangjiaoshensuo1"] = "伤害+1",
  ["xiangjiaoshensuo2"] = "伤害-1",
}

local mietianhai = General(extension, "ev__mietianhai", "ev", 4)
local wanxiangjinmie = fk.CreateTriggerSkill{
  name = "wanxiangjinmie",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local cards = EV.askforCardsChosenFromAreas(player, to, "hej")
    room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    --不知道为什么不触发清除标记，这里手动清除
    local shown = table.filter(to:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") ~= 0 end)
    if #shown == 0 then
      room:setPlayerMark(to, "@$shown", 0)
    else
      room:setPlayerMark(to, "@$shown", shown)
    end
    if U.hasFullRealCard(room, data.card) then
      room:moveCardTo(data.card, Card.PlayerHand, to, fk.ReasonJustMove, self.name, "", true)
      data.disresponsive = true
    end
  end,
}

local baoluanhuangquan = fk.CreateTriggerSkill{
  name = "baoluanhuangquan",
  frequency = Skill.Limited,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#baoluanhuangquan", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    to:showCards(to:getCardIds("h"))
    local n = #table.filter(to:getCardIds("h"), function (id) return Fk:getCardById(id).trueName == "slash" end)
    room:delay(100 * n)
    room:damage({
      from = player,
      to = to,
      damage = n,
      damageType = fk.NormalDamage,
      skillName = self.name,
    })
  end,
}

mietianhai:addSkill(wanxiangjinmie)
mietianhai:addSkill(baoluanhuangquan)

Fk:loadTranslationTable{
  ["ev__mietianhai"] = "蔑天骸",
  ["designer:ev__mietianhai"] = "烈火幽魂",
  ["wanxiangjinmie"] = "万象尽灭",
  [":wanxiangjinmie"] = "当你使用【杀】指定一个目标后，你可弃置其所有区域里的各一张牌，然后其获得此【杀】；若如此做，此【杀】不是【闪】的合法目标。",
  ["baoluanhuangquan"] = "暴乱黄泉",
  [":baoluanhuangquan"] = "限定技，结束阶段，你可展示一名其他角色的所有手牌并对其造成X点伤害（X为其手牌中【杀】的数量）。",
  ["#baoluanhuangquan"] = "暴乱黄泉：请选择处刑的目标角色",
}

local Kirigaya = General(extension, "ev__kirigaya", "ev", 4)

local erdaoliu = fk.CreateViewAsSkill{
  name = "erdaoliu",
  pattern = "slash,jink",
  interaction = function()
    local all_names = {"ev__slash","ev__jink"}
    local names = {}
    for _, name in ipairs(all_names) do
      local card = Fk:cloneCard(name)
      if Fk.currentResponsePattern ~= "jink" or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
        table.insertIfNeed(names, name)
      end
    end
    if #names == 0 then return end
    return U.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = function(self, to_select, selected)
    if Self:getMark("@@xingbaoqiliuzhan-turn") == 0 then
      local colors = Self:getTableMark("erdaoliu-turn")
      if table.contains(colors, Fk:getCardById(to_select):getColorString()) then return end
    else
      local names = Self:getTableMark("erdaoliu-turn")
      if table.contains(names, Fk:getCardById(to_select).trueName) then return end
    end
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function (self, player, response)
    return (player:usedSkillTimes(self.name) == 0 or player:getMark("@@xingbaoqiliuzhan-turn") > 0) and not response
  end,
}

local erdaoliu_trigger = fk.CreateTriggerSkill{
  name = "#erdaoliu_trigger",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
    and (player:getMark("erdaoliutimes-turn") == 0 or player:getMark("@@xingbaoqiliuzhan-turn") > 0)
  end,
  on_cost = function(self, event, target, player, data)
    local success, dat = player.room:askForUseActiveSkill(player, "erdaoliu", "#erdaoliu-slash", true)
    if success then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "erdaoliutimes-turn")
    local card = Fk.skills["erdaoliu"]:viewAs(self.cost_data.cards)
    player.room:useCard{
      from = player.id,
      tos = table.map(self.cost_data.targets, function(id) return {id} end),
      card = card,
      extraUse = true,
    }
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getTableMark("erdaoliu-turn")
    if player:getMark("@@xingbaoqiliuzhan-turn") > 0 then
      table.insertIfNeed(mark, data.card.trueName)
    else
      table.insertIfNeed(mark, data.card:getColorString())
    end
    player.room:setPlayerMark(player, "erdaoliu-turn", mark)
  end,
}

local xingbaoqiliuzhan = fk.CreateTriggerSkill{
  name = "xingbaoqiliuzhan",
  anim_type = "special",
  frequency = Skill.Limited,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Start and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
      return table.find(player.room.alive_players, function (p)
        return EV.isFriend(player, p) and p:isWounded()
      end)
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@@xingbaoqiliuzhan-turn")
  end,
}

local erdaoliu_tar = fk.CreateTargetModSkill{
  name = "#erdaoliu_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self) and skill.trueName == "slash_skill" and card and card.skillName == "erdaoliu" then
      return 999
    end
  end,
}

erdaoliu:addRelatedSkill(erdaoliu_trigger)
erdaoliu:addRelatedSkill(erdaoliu_tar)
Kirigaya:addSkill(erdaoliu)
Kirigaya:addSkill(xingbaoqiliuzhan)

Fk:loadTranslationTable{
  ["ev__kirigaya"] = "桐谷和人",
  ["designer:ev__kirigaya"] = "陆丿伯言",
  ["erdaoliu"] = "二刀流",
  ["#erdaoliu-slash"] = "你可将一张手牌当【杀】使用",
  [":erdaoliu"] = "<font color=\"#D2042D\">{回合技，}</font>当你使用的【杀】结算结束后/需要使用【闪】时，你可将一张手牌（颜色不得与你于此回合内使用过的牌相同）当【杀】/【闪】使用。",
  ["xingbaoqiliuzhan"] = "星爆气流斩",
  [":xingbaoqiliuzhan"] = "限定技，准备阶段，若有已受伤的己方角色，你可于本回合内：删除<font color=\"#D2042D\">{ }</font>里的描述，将“二刀流”中的“颜色”改为“牌名”。",
  ["@@xingbaoqiliuzhan-turn"] = "<font color=\"#D2042D\">星爆</font>",
}

local Violet = General(extension, "ev__violet", "ev", 4, 4, General.Female)

local zhanzhengzhishang = fk.CreateTriggerSkill{
  name = "zhanzhengzhishang",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMaxCards() ~= 0
  end,
  on_use = function(self, event, target, player, data)
    if player:getMark("AddMaxCards") > 0 then
      player.room:removePlayerMark(player, "AddMaxCards", 1)
    else
      player.room:addPlayerMark(player, "MinusMaxCards", 1)
    end
    player:drawCards(2, self.name)
  end,

  
}

local zhanzhengzhishang_fix = fk.CreateTriggerSkill{
  name = "zhanzhengzhishang_fix",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
  end,
}
--player.room:addPlayerMark(player, "AddMaxCards", 2)

local zhanzhengzhishang_maxcards = fk.CreateMaxCardsSkill{
  name = "#zhanzhengzhishang_maxcards",
  fixed_func = function(self, player)
    if player:hasSkill(self) then
      return player.maxHp
    end
  end
}

local renouyuai = fk.CreateTriggerSkill{
  name = "renouyuai",
  frequency = Skill.Wake,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Start and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return player:isWounded() and player:getMaxCards() == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
    room:handleAddLoseSkills(player, "aidetuidao|zhanzhengzhishang_fix|-zhanzhengzhishang")
  end,
}

local aidetuidao = fk.CreateTriggerSkill{
  name = "aidetuidao",
  refresh_events = {fk.EventAcquireSkill},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.name == self.name
  end,
  on_refresh = function(self, event, target, player, data)
    for _, p in ipairs(player.room:getOtherPlayers(player)) do
      player.room:handleAddLoseSkills(p, "aidetuidao&")
    end
  end,
}

local aidetuidao_get = fk.CreateActiveSkill{
  name = "aidetuidao&",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "你可将一张除【杀】外的手牌交给薇尔莉特",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName ~= "slash" and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):hasSkill("aidetuidao")
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = Fk:getCardById(effect.cards[1])
    room:obtainCard(target.id, card, false, fk.ReasonGive, player.id)
    if target.dead then return end
    if U.askForUseRealCard(room, target, effect.cards, ".", self.name, "#aidetuidao-use") then
      local suits = target:getTableMark("aidetuidao-suit")
      if not table.contains(suits, card:getSuitString()) then
        table.insert(suits, card:getSuitString())
        if target:getMark("MinusMaxCards") > 0 then
          room:removePlayerMark(target, "MinusMaxCards", 1)
        else
          room:addPlayerMark(target, "AddMaxCards", 1)
        end
      end
    end
  end
}

zhanzhengzhishang:addRelatedSkill(zhanzhengzhishang_maxcards)
zhanzhengzhishang_fix:addRelatedSkill(zhanzhengzhishang_maxcards)
Fk:addSkill(zhanzhengzhishang_fix)
Fk:addSkill(aidetuidao)
Fk:addSkill(aidetuidao_get)
Violet:addSkill(zhanzhengzhishang)
Violet:addSkill(renouyuai)
Violet:addRelatedSkill("aidetuidao")

Fk:loadTranslationTable{
  ["ev__violet"] = "薇尔莉特",
  ["designer:ev__violet"] = "zengyouyu",
  ["zhanzhengzhishang"] = "战争之殇",
  [":zhanzhengzhishang"] = "锁定技，你的初始手牌上限视为体力上限。当你<font color=\"#D2042D\">{造成或}</font>受到伤害后，<font color=\"#D2042D\">{若你的手牌上限不为0，}</font>你<font color=\"#D2042D\">{减少1点手牌上限并}</font>摸两张牌。",
  ["zhanzhengzhishang_fix"] = "战争之殇",
  [":zhanzhengzhishang_fix"] = "锁定技，你的初始手牌上限视为体力上限。当你受到伤害后，你摸两张牌。",
  ["renouyuai"] = "人偶与爱",
  [":renouyuai"] = "觉醒技，准备阶段，若你已受伤且你的手牌上限为0，你回复1点体力，删除<font color=\"#D2042D\">{ }</font>里的描述并获得“爱的推导”。",
  ["aidetuidao"] = "爱的推导",
  [":aidetuidao"] = "其他角色的出牌阶段限一次，其可将一张除【杀】外的手牌交给你，然后你可使用此牌；当你首次以此法使用一种花色的牌时，你增加1点手牌上限。",
  ["aidetuidao&"] = "爱的推导",
  [":aidetuidao&"] = "阶段技，你可将一张除【杀】外的手牌交给薇尔莉特。",
  ["#aidetuidao-use"] = "爱的推导：你可以使用此牌",
}

local Misaka = General(extension, "ev__misaka", "ev", 4, 4, General.Female)

local SuperThunderSlashSkill = fk.CreateActiveSkill{
  name = "super_thunder__slash_skill",
  prompt = "对对手造成1点伤害",
  max_phase_use_time = 1,
  min_target_num = 1,
  can_use = Fk:cloneCard("slash").skill.canUse,
  mod_target_filter = Fk:cloneCard("slash").skill.modTargetFilter,
  target_filter = function (self, to_select, selected, _, card, _, player)
    if to_select == player.id then return false end
    local target = Fk:currentRoom():getPlayerById(to_select)
    if #selected == 0 then
      return true
    else
      return Fk:currentRoom():getPlayerById(selected[#selected]):getNextAlive() == target or target:getNextAlive().id == selected[#selected]
    end
  end,
  feasible = function(self, selected)
    if #selected > 0 then
      local p1 = Fk:currentRoom():getPlayerById(selected[1])
      if #selected == 1 then return true end
      if #selected > 1 then
        if p1:getLastAlive() == Fk:currentRoom():getPlayerById(selected[2]) then
          for i = 1, #selected - 1, 1 do
            if Fk:currentRoom():getPlayerById(selected[i]):getLastAlive() ~= Fk:currentRoom():getPlayerById(selected[i+1]) then
              return false
            end
          end
          return true
        end
        if p1:getNextAlive() == Fk:currentRoom():getPlayerById(selected[2]) then
          for i = 1, #selected - 1, 1 do
            if Fk:currentRoom():getPlayerById(selected[i]):getNextAlive() ~= Fk:currentRoom():getPlayerById(selected[i+1]) then
              return false
            end
          end
          return true
        end
      end
    end
  end,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = fk.ThunderDamage,
      skillName = self.name
    })
  end
}

local SuperThunderSlash = fk.CreateBasicCard{
  name = "&super_thunder__slash",
  skill = SuperThunderSlashSkill,
  is_damage_card = true,
  is_derived = true,
}

SuperThunderSlash.package = extension
Fk:addSkill(SuperThunderSlashSkill)
Fk:addCard(SuperThunderSlash)

local electrans = fk.CreateTriggerSkill{
  name = "electrans",
  events = {fk.Damaged, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damaged then 
      return player:hasSkill(self) and #data.to:getCardIds(Player.Equip) > 0 and data.damageType == fk.ThunderDamage
    else
      return player:hasSkill(self) and target == player and player.phase == Player.Start
      and #table.filter(player:getCardIds("he"),function(id) return Fk:getCardById(id).type == Card.TypeEquip end) > 0
      and #table.filter(player.room.discard_pile,function(id) return Fk:getCardById(id).type == Card.TypeEquip end) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then 
      local id = room:askForCardChosen(player, data.to, "e", self.name)
      if id then
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      end
    else
      local equips = table.filter(player:getCardIds("he"),function(id) return Fk:getCardById(id).type == Card.TypeEquip end)
      local cards = table.filter(player.room.discard_pile,function(id) return Fk:getCardById(id).type == Card.TypeEquip end)
      --[[local cids = room:askForArrangeCards(player, self.name,
      {cards, equips, self.name, player.general}, "#electrans-exchange", true)
      U.swapCardsWithPile(player, cids[1], cids[2], self.name, "discardPile", true, player.id)]]
      local cids = U.askForExchange(player, self.name, player.general, cards, equips, "#electrans-exchange", 1, true)
      if #cids > 0 then
        equips = table.filter(cids, function (id)
          return table.contains(player:getCardIds("he"), id)
        end)
        cards = table.filter(cids, function (id)
          return not table.contains(player:getCardIds("he"), id)
        end)
        U.swapCardsWithPile(player, equips, cards, self.name, "discardPile", true, player.id)
      end
    end
  end,
}

local Railgun = fk.CreateViewAsSkill{
  name = "railgun",
  anim_type = "offensive",
  pattern = "ev__slash",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).suit == Card.Spade or Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local pattern = "ev_thunder__slash"
    if Fk:getCardById(cards[1]).suit == Card.Spade and Fk:getCardById(cards[1]).type == Card.TypeEquip then
      pattern = "super_thunder__slash"
    end
    local card = Fk:cloneCard(pattern)
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
}
Misaka:addSkill(electrans)
Misaka:addSkill(Railgun)

Fk:loadTranslationTable{
  ["ev__misaka"] = "御坂美琴",
  ["designer:ev__misaka"] = "zengyouyu",
  ["super_thunder__slash"] = "雷杀",
  [":super_thunder__slash"] = "御坂美琴专用雷杀，可指定连续相邻的至少两名其他角色",
  ["electrans"] = "电磁转换",
  [":electrans"] = "当一名角色受到雷电伤害时，你可弃置其装备区里的一张牌。准备阶段，你可用一张装备牌替换弃牌堆里的一张装备牌。",
  ["#electrans-exchange"] = "你可用一张装备牌替换弃牌堆里的一张装备牌",
  ["railgun"] = "超电磁炮",
  [":railgun"] = "你可将一张黑桃牌或装备牌当雷【杀】使用或打出；若此牌为黑桃装备牌，此雷【杀】的“使用目标”后增加“或连续相邻的至少两名其他角色”。",
}

local Artorias = General(extension, "ev__artorias", "ev", 4)

local shenyuanmanbuzhe = fk.CreateTriggerSkill{
  name = "shenyuanmanbuzhe",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TargetSpecified then
        return player:getHandcardNum() >= player.hp and #AimGroup:getAllTargets(data.tos) == 1 and not player.room:getPlayerById(data.to):isAllNude()
      else
        return player:getHandcardNum() < player.hp and player.id ~= data.from
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return player.room:askForSkillInvoke(player, self.name, nil, "#shenyuanmanbuzhe::"..data.to)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local to = room:getPlayerById(data.to)
      local id = room:askForCardChosen(player, to, "hej", self.name)
      if id then
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      end
    else
      --data.disresponsive = true
      data.disresponsiveList = data.disresponsiveList or {}
      table.insertIfNeed(data.disresponsiveList, player.id)
    end
  end,
}

local shenyuanqinshi = fk.CreateTriggerSkill{
  name = "shenyuanqinshi",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function (p)
      return p:distanceTo(player) == 1
    end), Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#shenyuanqinshi", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    room:handleAddLoseSkills(to, "shenyuanmanbuzhe")
    room:addPlayerMark(to, "shenyuanqinshi-buff")
  end,

  refresh_events = {fk.TurnStart, fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target:hasSkill("shenyuanmanbuzhe") and target:getMark("shenyuanqinshi-buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      player.room:addPlayerMark(target, "shenyuanqinshi-turn")
    else
      if target:getMark("shenyuanqinshi-turn") > 0 then
        player.room:handleAddLoseSkills(target, "-shenyuanmanbuzhe")
      end
      player.room:setPlayerMark(target, "shenyuanqinshi-buff", 0)
    end
  end,
}

Artorias:addSkill(shenyuanmanbuzhe)
Artorias:addSkill(shenyuanqinshi)

Fk:loadTranslationTable{
  ["ev__artorias"] = "阿尔特留斯",
  ["designer:ev__artorias"] = "路人orz",
  ["shenyuanmanbuzhe"] = "深渊漫步者",
  [":shenyuanmanbuzhe"] = "当你使用牌指定唯一目标后/成为其他角色使用牌的目标后，若你的手牌数不小于/小于体力值，你可弃置其区域里的一张牌/你不能对此牌使用牌。",
  ["#shenyuanmanbuzhe"] = "你可弃置%dest区域里的一张牌",
  ["shenyuanqinshi"] = "深渊侵蚀",
  ["#shenyuanqinshi"] = "你可令与你距离为1的一名角色获得“深渊漫步者”",
  [":shenyuanqinshi"] = "准备阶段，你可选择与你距离为1的一名角色，令其获得“深渊漫步者”直至其下回合结束。",
}

local QB = General(extension, "ev__QB", "ev", 1, 1, General.Agender)

local monvquanyou = fk.CreateActiveSkill{
  name = "monvquanyou",
  prompt = "#qianlizhishi-prompt",
  target_num = 1,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_filter = function(self, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and target.gender == General.Female and not target:hasSkill("linghunqiyue") and not target:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = room:askForCard(target, 1, 1, false, self.name, false, ".", "#monvquanyou")
    if #card > 0 then
      target:showCards(card)
      if Fk:getCardById(card[1]).color == Card.Red then
        local choices = {"draw2"}
        if target:isWounded() then
          table.insert(choices, "recover")
        end
        local choice = room:askForChoice(target, choices, self.name)
        if choice == "draw2" then
          target:drawCards(2, self.name)
        else
          room:recover({
            who = target,
            num = 1,
            recoverBy = player,
            skillName = self.name
          })
        end
        room:handleAddLoseSkills(target, "linghunqiyue")
        room:addPlayerMark(player, "@@linghunqiyue")
      end
    end
  end,
}

local linghunqiyue = fk.CreateTriggerSkill{
  name = "linghunqiyue",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted, fk.AfterCardsMove, fk.Death},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@@linghunqiyue") > 0 then return end
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        local choices = {}
        if player:hasSkill(self) and move.from and player.room:getPlayerById(move.from):isAlive() and player.id == move.from then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return player:isKongcheng()
            end
          end
        end
      end
    else
      if event == fk.DamageInflicted then
        return target == player and player:hasSkill(self) and not player:isKongcheng()
      else
        return target == player and player:hasSkill(self, true, true) and not player:isNude()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      room:loseHp(player, 1, self.name)
    elseif event == fk.Death then
      for _, p in ipairs(room.alive_players) do
        if p.general == "ev__QB" and not player:isNude() then
          local card = room:askForCardChosen(p, player, "he", self.name)
          p:addToPile("fushugeti", card, true, self.name)
        end
      end
    elseif event == fk.DamageInflicted then
      local cards = table.filter(player:getCardIds("h"), function (id) return Fk:getCardById(id).color == Card.Red end)
      if #cards > 0 then
        local cards = room:askForCard(player, 1, 1, false, self.name, false, tostring(Exppattern{ id = cards }) , "#linghunqiyue-throw")
        if #cards > 0 then
          room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
          data.damage = data.damage - 1
        end
      end
    end
  end
}

local fushugeti = fk.CreateTriggerSkill{
  name = "fushugeti",
  derived_piles = {"fushugeti"},
  frequency = Skill.Compulsory,
  events = {fk.GameStart, fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(self)
    else
      return player:hasSkill(self) and target == player and #player:getPile("fushugeti") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      player:addToPile("fushugeti", room:getNCards(5), true, self.name)
    else
      local cards = player.room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|fushugeti|.|.", "#fushugeti-invoke", "fushugeti")
      if #cards > 0 then
        room:moveCardTo(cards, Player.Hand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
        room:recover({
          who = player,
          num = 1 - player.hp,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
  end,
}
QB:addSkill(monvquanyou)
QB:addSkill(linghunqiyue)
QB:addSkill(fushugeti)

Fk:loadTranslationTable{
  ["ev__QB"] = "QB",
  ["designer:ev__QB"] = "KINGDOM43",
  ["monvquanyou"] = "魔女劝诱",
  ["#monvquanyou"] = "魔女劝诱：请展示一张手牌",
  [":monvquanyou"] = "阶段技，你可令没有“灵魂契约”的一名女性角色展示一张手牌，若为红色，其可选择一项：1.摸两张牌；2.回复1点体力，然后其获得“灵魂契约”，你的“灵魂契约”失效。",
  ["#shenyuanmanbuzhe"] = "你可弃置%dest区域里的一张牌",
  ["linghunqiyue"] = "灵魂契约",
  [":linghunqiyue"] = "锁定技，当你：受到伤害时，你弃置一张红色手牌令此伤害-1；失去手牌后，若你没有手牌，你失去1点体力；死亡时，QB将你的一张牌置于其角色牌上。",
  ["#linghunqiyue-throw"] = "请弃置一张红色手牌令此伤害-1",
  ["@@linghunqiyue"] = "<font color=\"#DE3163\">灵魂契约失效</font>",
  ["fushugeti"] = "复数个体",
  [":fushugeti"] = "锁定技，游戏开始时，你将牌堆顶的五张牌置于角色牌上；当你进入濒死状态时，你获得一张角色牌上的牌，然后将体力回复至1点。",
  ["#fushugeti-invoke"] = "请选择一张角色牌上的牌获得之",
}

local selina = General(extension, "ev__selina", "ev", 3, 3, General.Female)

local ev__juezhi = fk.CreateTriggerSkill{
  name = "ev__juezhi",
  mute = true,
  events = {fk.EventPhaseStart, fk.EventPhaseEnd, fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return target.phase == Player.Play and not player:isKongcheng()
      elseif event == fk.EventPhaseEnd then
        return target.phase == Player.Play and target:getMark("juezhi-phase") > 0
      else
        return data.card:getMark("juezhi-use") > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      local cards = player.room:askForCard(player, player.hp, player.hp, true, self.name, true,
      ".|.|.|.|.|.|" .. table.concat(unshown, ","), "#ev__juezhi-show:::"..player.hp)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:addPlayerMark(player, "juezhi-phase")
      room:notifySkillInvoked(player, self.name, "special")
      EV.OpenCards(room, player, self.cost_data, self.name)
    elseif event == fk.EventPhaseEnd then
      local shown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
      if #shown > 0 then
        room:moveCardTo(shown, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      else
        room:addPlayerMark(player, "AddMaxCards-turn", 1)
      end
    else
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(1, self.name)
    end
  end,
  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card:getMark("@@shown-inhand") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local typesRecorded = player:getTableMark("@[cardtypes]juezhi-turn")
    if not table.contains(typesRecorded, data.card.type) then
      table.insert(typesRecorded, data.card.type)
      player.room:setCardMark(data.card, "juezhi-use", 1)
    end
    player.room:setPlayerMark(player, "@[cardtypes]juezhi-turn", typesRecorded)
  end 
}

local ev__jieyi = fk.CreateTriggerSkill{
  name = "ev__jieyi",
  anim_type = "drawcard",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target.phase == Player.Discard then
      local room = player.room
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      local end_id = turn_event.id
      local ids = {}
      U.getEventsByRule(room, GameEvent.MoveCards, 999, function (e)
        for _, move in ipairs(e.data) do
          if move.from and move.from == target.id and move.moveReason == fk.ReasonDiscard then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                table.insert(ids, info.cardId)
              end
            end
          end
        end
        return false
      end, end_id)
      return #ids >= target.hp
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    target:drawCards(1, self.name)
    U.askForPlayCard(room, target, target:getHandlyIds(true), ".", self.name)
  end,
}

selina:addSkill(ev__juezhi)
selina:addSkill(ev__jieyi)

Fk:loadTranslationTable{
  ["ev__selina"] = "莎莉娜",
  ["designer:ev__selina"] = "潜水员最棒",
  ["ev__juezhi"] = "决志",
  [":ev__juezhi"] = "出牌阶段开始时，你可明置X张手牌，则本阶段结束时，若你没有/有明置手牌，则你的手牌上限于本回合内+1/你弃置所有明置手牌（X为你的体力值）。当你于当前回合内首次使用一种类别的明置手牌时，你摸一张牌。",
  ["#ev__juezhi-show"] = "决志：你可明置%arg张手牌",
  ["@[cardtypes]juezhi-turn"] = "决志",
  ["ev__jieyi"] = "解意",
  [":ev__jieyi"] = "一名角色的弃牌阶段结束时，若其于本回合内弃置的牌数不小于体力值，你可令其摸一张牌，然后其可使用一张牌。",
}

local yunru = General(extension, "ev__yunru", "ev", 3, 3, General.Female)

local ev__rouzhi = fk.CreateTriggerSkill{
  name = "ev__rouzhi",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and target:inMyAttackRange(player) and target.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, true, self.name, true, ".", "#ev__rouzhi::"..target.id)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local color = Fk:getCardById(self.cost_data):getColorString()
    player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, nil, true, player.id)
    local mark = target:getTableMark("ev__rouzhi-turn")
    table.insertIfNeed(mark, color)
    player.room:setPlayerMark(target, "ev__rouzhi-turn", mark)
  end,
}

local rouzhi_prohibit = fk.CreateProhibitSkill{
  name = "#ev__rouzhi_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("ev__rouzhi-turn") ~= 0 and card then
      return table.contains(player:getTableMark("ev__rouzhi-turn"), card:getColorString())
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("ev__rouzhi-turn") ~= 0 and card then
      return table.contains(player:getTableMark("ev__rouzhi-turn"), card:getColorString())
    end
  end,
}

local ev__jingzhen = fk.CreateTriggerSkill{
  name = "ev__jingzhen",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      local end_id = turn_event.id
      return #U.getEventsByRule(player.room, GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.from and move.from == player.id and (move.to == nil or move.to ~= player.id) then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId).type == Card.TypeEquip and (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
                return true
              end
            end
          end
        end
        return false
      end, end_id) > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 99, "#ev__jingzhen-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(self.cost_data) do
      local to = room:getPlayerById(p)
      if #to:getCardIds(Player.Equip) > 0 and not to.dead then
        local card = room:askForCard(to, 1, 1, true, self.name, false, ".|.|.|equip", "#ev__jingzhen")
        room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonJustMove, self.name, "", true, p)
      end
    end
    for _, p in ipairs(self.cost_data) do
      local to = room:getPlayerById(p)
      if not to.dead and not to:isKongcheng() then
        local id = room:askForCardChosen(player, to, "h", self.name)
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      end
    end
  end,
}

ev__rouzhi:addRelatedSkill(rouzhi_prohibit)
yunru:addSkill(ev__rouzhi)
yunru:addSkill(ev__jingzhen)

Fk:loadTranslationTable{
  ["ev__yunru"] = "云茹",
  ["designer:ev__yunru"] = "子规枝上",
  ["ev__rouzhi"] = "柔制",
  [":ev__rouzhi"] = "其他角色的出牌阶段开始时，若其攻击范围内含有你，你可弃置一张牌，令其于此回合内不能使用或打出与之颜色相同的牌。",
  ["#ev__rouzhi"] = "柔制：你可弃置一张牌，令%dest于此回合内不能使用或打出与之颜色相同的牌",
  ["#ev__rouzhi_prohibit"] = "柔制",
  ["ev__jingzhen"] = "惊震",
  [":ev__jingzhen"] = "回合技（终），若你于此回合内失去过装备牌，你可选择任意名角色，令这些角色各获得其自己装备区里的一张牌，然后你弃置这些角色的各一张手牌。",
  ["#ev__jingzhen-choose"] = "惊震：你可选择任意名角色",
  ["#ev__jingzhen"] = "惊震：请选择装备区里的一张牌获得",
}

local Kallen = General(extension, "ev__kallen", "ev", 4, 4, General.Female)

local shengnvjueyi = fk.CreateViewAsSkill{
  name = "shengnvjueyi",
  card_num = 0,
  card_filter = Util.FalseFunc,
  pattern = "^nullification",
  interaction = function()
    local all_names = U.getAllCardNames("b")
    local names = table.simpleClone(all_names)
    table.removeOne(names, "ev__poison")
    return U.CardNameBox { choices = names }
  end,
  view_as = function(self, cards)
    if #cards ~= 0 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    EV.OpenCards(player.room, player, player:getCardIds("h"), self.name)
  end,
  enabled_at_play = function(self, player)
    return table.every(player:getCardIds("h"), function (id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    and not player:isKongcheng()
  end,
  enabled_at_response = function(self, player, response)--FIXME：pattern解析目前有问题
    return table.every(player:getCardIds("h"), function (id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    and not player:isKongcheng()
  end,
}

local xinyangzhihu = fk.CreateTriggerSkill{
  name = "xinyangzhihu",
  anim_type = "defensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.card.trueName == "slash" and target ~= player and #AimGroup:getAllTargets(data.tos) == 1
    and player:usedSkillTimes(self.name) < player.maxHp then
      local to = player.room:getPlayerById(AimGroup:getAllTargets(data.tos)[1])
      if EV.isFriend(player, to) then
        local friends = table.filter(player.room.alive_players, function (p) return EV.isFriend(player, p) end)
        return table.every(friends, function (p) return p.hp >= to.hp end)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --EV.nullifiedCard(data, data.card, player)
    data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
    if target:isAlive() then
      if room:getCardArea(data.card) == Card.Processing then
        room:moveCardTo(data.card, Card.PlayerHand, target, fk.ReasonJustMove, self.name, "", true)
      end
      room:useVirtualCard("ev__duel", nil, player, target, self.name, false)
    end
  end,
}

Kallen:addSkill(shengnvjueyi)
Kallen:addSkill(xinyangzhihu)

Fk:loadTranslationTable{
  ["ev__kallen"] = "卡莲",
  ["designer:ev__kallen"] = "陆丿伯言",
  ["shengnvjueyi"] = "圣女决意",
  [":shengnvjueyi"] = "当你需要使用或打出除【毒】外的基础牌时，若你的手牌均暗置，你可明置所有手牌，视为使用或打出此牌。",
  ["xinyangzhihu"] = "信仰之护",
  [":xinyangzhihu"] = "回合技（X），其他角色使用【杀】指定唯一目标后，若此【杀】的目标为己方角色中体力值最小的角色，你可令此【杀】无效；然后你令此【杀】的使用者获得之，视为对其使用【决斗】（X为你的体力上限）。",
}

local Mash = General(extension, "ev__mash", "ev", 4, 4, General.Female)

local fenyizhidun = fk.CreateTriggerSkill{
  name = "fenyizhidun",
  events = {fk.TargetConfirming, fk.Damaged},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and not player:isKongcheng() then
      if event == fk.TargetConfirming then
        if EV.isFriend(player, target) or player == target then
          return (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and data.from ~= player.id
          and player.room:getPlayerById(data.from):inMyAttackRange(player)
        end
      else
        return target == player
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      local card = room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = unshown }), "#fenyizhidun:::"..data.card:toLogString())
      if #card > 0 then
        self.cost_data = card
        return true
      end
    else
      local cards = room:askForCard(player, 1, 999, false, self.name, true, ".", "#fenyizhidun-discard")
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      EV.OpenCards(room, player, self.cost_data, self.name)
      if player ~= target then
        room:doIndicate(target.id, { player.id })
        TargetGroup:removeTarget(data.targetGroup, target.id)
        TargetGroup:pushTargets(data.targetGroup, player.id)
      end
    else
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      local cards = player:drawCards(#self.cost_data, self.name)
      local card = room:askForCard(player, 1, #cards, true, self.name, true, tostring(Exppattern{ id = cards }), "#fenyizhidun-show")
      if #card > 0 then
        EV.OpenCards(room, player, card, self.name)
      end
    end
  end,
}

local yaoyuanzhicheng = fk.CreateTriggerSkill{
  name = "yaoyuanzhicheng",
  events = {fk.TargetConfirmed},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and not player:isKongcheng() then
      return data.card.type ~= Card.TypeEquip and table.find(player:getCardIds("h"), function (id)
        return Fk:getCardById(id):getMark("@@shown-inhand") > 0 and Fk:getCardById(id).number == data.card.number
      end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#yaoyuanzhicheng:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    --table.insertIfNeed(data.nullifiedTargets, player.id)
    EV.nullifiedCard(data, data.card, player)
  end,
}

local yaoyuanzhicheng_maxcards = fk.CreateMaxCardsSkill{
  name = "#yaoyuanzhicheng_maxcards",
  exclude_from = function(self, player, card)
    return player:hasSkill(self) and card:getMark("@@shown-inhand") > 0
  end,
}

yaoyuanzhicheng:addRelatedSkill(yaoyuanzhicheng_maxcards)
Mash:addSkill(fenyizhidun)
Mash:addSkill(yaoyuanzhicheng)

Fk:loadTranslationTable{
  ["ev__mash"] = "玛修",
  ["designer:ev__mash"] = "zengyouyu",
  ["fenyizhidun"] = "奋意之盾",
  [":fenyizhidun"] = "当己方角色成为基础牌或即时魔法牌的目标时，若此牌的使用者不为你且其攻击范围内含有你，你可明置一张手牌，将此牌转移给你。当你受到伤害后，你可弃置任意张手牌，然后摸等量张牌，明置其中的任意张牌。",
  ["#fenyizhidun"] = "你可以将%arg转移给你",
  ["#fenyizhidun-discard"] = "你可以弃置任意张手牌，摸等量的牌",
  ["#fenyizhidun-show"] = "奋意之盾：你可以明置其中任意张牌",
  ["yaoyuanzhicheng"] = "遥远之城",
  ["#yaoyuanzhicheng"] = "遥远之城：你可令%arg对你无效",
  [":yaoyuanzhicheng"] = "你的明置手牌不计入手牌上限；当你成为非装备牌的目标后，若你有与此牌点数相同的明置手牌，则你可令此牌对你无效。",
}

local Accelerator = General(extension, "ev__accelerator", "ev", 3, 3, General.Agender)

local shiliangcaozong = fk.CreateTriggerSkill{
  name = "shiliangcaozong",
  events = {fk.TargetSpecifying, fk.TargetConfirming},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.type == Card.TypeBasic
  end,
  on_cost = function(self, event, target, player, data)
    local card
    if player:usedSkillTimes("juejingzhifen", Player.HistoryGame) == 0 then
      local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      card = player.room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = unshown }), "#shiliangcaozong-show:::"..data.card:toLogString())
    else
      card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#shiliangcaozong-discard:::"..data.card:toLogString())
    end
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:usedSkillTimes("juejingzhifen", Player.HistoryGame) == 0 then
      EV.OpenCards(room, player, self.cost_data, self.name)
    else
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    end
    local n = math.abs(Fk:getCardById(self.cost_data[1]).number - data.card.number)
    local targets = {}
    if data.from ~= data.to then
      table.insertIfNeed(targets, data.from)
    end
    local to = room:getPlayerById(data.to)
    for _, p in ipairs(room:getOtherPlayers(to)) do
      if to:distanceTo(p) == n then
        table.insertIfNeed(targets, p.id)
      end
    end
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, targets, 1, 99, "#shiliangcaozong-choose", self.name, true)
      local victim = targets[1]
      if tos and #tos > 0 then
        victim = tos[1]
      end
      room:doIndicate(data.to, { victim })
      TargetGroup:removeTarget(data.targetGroup, data.to)
      TargetGroup:pushTargets(data.targetGroup, victim)
    end
  end,
}

local juejingzhifen = fk.CreateTriggerSkill{
  name = "juejingzhifen",
  frequency = Skill.Wake,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Start and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return player.hp == 1 or player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "heibaishuangyi")
  end,
}

local heibaishuangyi = fk.CreateTriggerSkill{
  name = "heibaishuangyi",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and data.card.type ~= Card.TypeEquip and #AimGroup:getAllTargets(data.tos) == 1 then
      if data.card.color == Card.Red then
        return player.room:getPlayerById(data.to).hp <= 1
      elseif data.card.color == Card.Black then  
        return player.hp <= 1
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if data.card.color == Card.Red then
      return player.room:askForSkillInvoke(player, self.name, nil, "#heibaishuangyi-red::"..data.to)
    elseif data.card.color == Card.Black then
      return player.room:askForSkillInvoke(player, self.name, nil, "#heibaishuangyi-black:::"..data.card:toLogString())
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.card.color == Card.Red and room:getPlayerById(data.to):isWounded() then
      room:recover({
        who = room:getPlayerById(data.to),
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    elseif data.card.color == Card.Black then
      player:drawCards(1, self.name)
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
  end,
}

Fk:addSkill(heibaishuangyi)
Accelerator:addSkill(shiliangcaozong)
Accelerator:addSkill(juejingzhifen)
Accelerator:addRelatedSkill("heibaishuangyi")

Fk:loadTranslationTable{
  ["ev__accelerator"] = "一方通行",
  ["designer:ev__accelerator"] = "KINGDOM43",
  ["shiliangcaozong"] = "矢量操纵",
  [":shiliangcaozong"] = "当你指定或成为基础牌的目标时，你可明置一张手牌，将此牌转移给此牌的使用者，或与目标角色距离为这两张牌点数之差的一名其他角色。",
  ["#shiliangcaozong-show"] = "你可明置一张手牌，将%arg目标转移给使用者或特定距离角色",
  ["#shiliangcaozong-discard"] = "你可弃置一张手牌，将%arg目标转移给使用者或特定距离角色",
  ["#shiliangcaozong-choose"] = "请选择使用者或距离为点数之差的一名其他角色",
  ["juejingzhifen"] = "绝境之奋",
  [":juejingzhifen"] = "觉醒技，准备阶段，若你的体力值为1或没有手牌，你将“矢量操纵”中的“明置”改为“弃置”并获得“黑白双翼”。",
  ["heibaishuangyi"] = "黑白双翼",
  [":heibaishuangyi"] = "当你使用黑色/红色非装备牌指定唯一目标后，若你/目标角色的体力值不大于1，则你可摸一张牌并令此牌造成的伤害+1/令其回复1点体力。",
  ["#heibaishuangyi-red"] = "你可以令%dest回复1点体力",
  ["#heibaishuangyi-black"] = "你可以摸一张牌并令%arg造成的伤害+1",
}

return extension
